RAIS  3.2
C:/Projekte/RAIS/dataaccesslayertest/UserManagementTest.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Data.SqlClient;
00004 using System.Text;
00005 using System.Xml;
00006 using NUnit.Framework;
00007 using RAIS.Common.UserManagement;
00008 using RAIS.DataAccessLayer;
00009 
00010 using UserTypes = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.UserTypeData>;
00011 using Users = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.UserData>;
00012 using FunctionRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole>;
00013 using DataRoles = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.DataRole>;
00014 using FunctionRoleCategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Category>;
00015 using FunctionRoleSubcategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Subcategory>;
00016 using Masks = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Mask>;
00017 using Regions = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Region>;
00018 using Districts = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.District>;
00019 using Facilities = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.Facility>;
00020 
00021 namespace RAIS.DataAccessLayerTest
00022 {
00023         [TestFixture]
00024         public class UserManagementTest
00025         {
00026                 #region Properties
00027                 [Test]
00028                 public void UserTypeAdminstrator()
00029                 {
00030                         // Preparations
00031                         /*UserData.UserType expectedType = UserData.UserType.Admin;
00032                         int expectedID = 1;
00033                         string expectedVisibleName = "Administrator";
00034 
00035                         // Test
00036                         UserTypes userTypes = UserManagement.UserTypes;
00037 
00038                         // Checks
00039                         Assert.AreEqual(expectedID, userTypes[expectedVisibleName].ID);
00040                         Assert.AreEqual(expectedType, userTypes[expectedVisibleName].Type);
00041                         Assert.AreEqual(expectedVisibleName, userTypes[expectedVisibleName].VisibleName);*/
00042                 }
00043                 [Test]
00044                 public void UserTypeRegulator()
00045                 {
00046                         // Preparations
00047                         UserData.UserType expectedType = UserData.UserType.Regulator;
00048                         int expectedID = 2;
00049                         string expectedVisibleName = "Regulator";
00050 
00051                         // Test
00052                         UserTypes userTypes = UserManagement.UserTypes;
00053 
00054                         // Checks
00055                         Assert.AreEqual(expectedID, userTypes[expectedVisibleName].ID);
00056                         Assert.AreEqual(expectedType, userTypes[expectedVisibleName].Type);
00057                         Assert.AreEqual(expectedVisibleName, userTypes[expectedVisibleName].VisibleName);
00058                 }
00059                 [Test]
00060                 public void UserTypeLicensee()
00061                 {
00062                         // Preparations
00063                         UserData.UserType expectedType = UserData.UserType.Licensee;
00064                         int expectedID = 3;
00065                         string expectedVisibleName = "Licensee";
00066 
00067                         // Test
00068                         UserTypes userTypes = UserManagement.UserTypes;
00069 
00070                         // Checks
00071                         Assert.AreEqual(expectedID, userTypes[expectedVisibleName].ID);
00072                         Assert.AreEqual(expectedType, userTypes[expectedVisibleName].Type);
00073                         Assert.AreEqual(expectedVisibleName, userTypes[expectedVisibleName].VisibleName);
00074                 }
00075                 /*[Test]
00076                 public void UserTypePublicBody()
00077                 {
00078                         // Preparations
00079                         UserData.UserType expectedType = UserData.UserType.PublicBody;
00080                         int expectedID = 4;
00081                         string expectedVisibleName = "Public Body";
00082 
00083                         // Test
00084                         UserTypes userTypes = UserManagement.UserTypes;
00085 
00086                         // Checks
00087                         Assert.AreEqual(expectedID, userTypes[expectedVisibleName].ID);
00088                         Assert.AreEqual(expectedType, userTypes[expectedVisibleName].Type);
00089                         Assert.AreEqual(expectedVisibleName, userTypes[expectedVisibleName].VisibleName);
00090                 }*/
00091                 [Test]
00092                 public void UserTypeGuest()
00093                 {
00094                         // Preparations
00095                         UserData.UserType expectedType = UserData.UserType.Guest;
00096                         int expectedID = 5;
00097                         string expectedVisibleName = "Guest";
00098 
00099                         // Test
00100                         UserTypes userTypes = UserManagement.UserTypes;
00101 
00102                         // Checks
00103                         Assert.AreEqual(expectedID, userTypes[expectedVisibleName].ID);
00104                         Assert.AreEqual(expectedType, userTypes[expectedVisibleName].Type);
00105                         Assert.AreEqual(expectedVisibleName, userTypes[expectedVisibleName].VisibleName);
00106                 }
00107                 [Test]
00108                 public void Users()
00109                 {
00110                         // Clear DB
00111                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00112 
00113                         // Preparations
00114                         int expectedCount = 3;
00115 
00116                         UserData[] expectedUsers = new UserData[expectedCount];
00117                         for (int i = 0; i < expectedCount; i++)
00118                                 expectedUsers[i] = TestUtilities.NewTestUserWithSave(i);
00119 
00120                         // Test
00121                         Users checkUsers = UserManagement.Users;
00122 
00123                         // Checks
00124                         Assert.AreEqual(expectedCount, checkUsers.Count, "Wrong Users count:");
00125 
00126                         for (int i = 0; i < expectedCount; i++)
00127                                 Assert.AreEqual(expectedUsers[i].Name, checkUsers[expectedUsers[i].Login].Name);
00128 
00129                         // Restore to previous state
00130                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00131                 }
00132                 [Test]
00133                 public void FunctionRoles()
00134                 {
00135                         // Clear DB
00136                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00137 
00138                         // Preparations
00139                         int expectedCount = 3;
00140 
00141                         FunctionRole[] expectedFunctionRoles = new FunctionRole[expectedCount];
00142                         for (int i = 0; i < expectedCount; i++ )
00143                                 expectedFunctionRoles[i] = TestUtilities.NewTestFunctionRoleWithSave(i);
00144 
00145                         // Test
00146                         FunctionRoles checkFunctionRoles = UserManagement.FunctionalRoles;
00147 
00148                         // Checks
00149                         Assert.AreEqual(expectedCount, checkFunctionRoles.Count, "Wrong FunctionRoles count:");
00150 
00151                         for (int i = 0; i < expectedCount; i++)
00152                                 Assert.AreEqual(expectedFunctionRoles[i].Name, checkFunctionRoles[expectedFunctionRoles[i].Name].Name);
00153 
00154                         // Restore to previous state
00155                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00156                 }
00157                 [Test]
00158                 public void FunctionRoleCategories()
00159                 {
00160                         // Clear DB
00161                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00162 
00163                         // Preparations
00164                         int expectedCount = 4;
00165 
00166                         FunctionRole.Category[] expectedCategories = new FunctionRole.Category[expectedCount];
00167                         for (int i = 0; i < expectedCount - 1; i++)
00168                                 expectedCategories[i] = TestUtilities.NewTestCategoryWithSave(i);
00169 
00170                         // Test
00171                         FunctionRoleCategories checkCategories = UserManagement.FunctionalRoleCategories;
00172 
00173                         // Checks
00174                         Assert.AreEqual(expectedCount, checkCategories.Count, "Wrong Categories count:");
00175 
00176                         for (int i = 0; i < expectedCount - 1; i++)
00177                                 Assert.AreEqual(expectedCategories[i].Name, checkCategories[expectedCategories[i].Name].Name);
00178 
00179                         // Restore to previous state
00180                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00181                 }
00182                 [Test]
00183                 public void DataRoles()
00184                 {
00185                         // Clear DB
00186                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00187 
00188                         // Preparations
00189                         int expectedCount = 3;
00190 
00191                         DataRole[] expectedDataRoles = new DataRole[expectedCount];
00192                         for (int i = 0; i < expectedCount; i++)
00193                                 expectedDataRoles[i] = TestUtilities.NewTestDataRoleWithSave(i);
00194 
00195                         // Test
00196                         DataRoles checkDataRoles = UserManagement.DataRoles;
00197 
00198                         // Checks
00199                         Assert.AreEqual(expectedCount, checkDataRoles.Count, "Wrong DataRoles count:");
00200 
00201                         for (int i = 0; i < expectedCount; i++)
00202                                 Assert.AreEqual(expectedDataRoles[i].Name, checkDataRoles[expectedDataRoles[i].Name].Name);
00203 
00204                         // Restore to previous state
00205                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00206                 }
00207                 [Test]
00208                 public void Regions()
00209                 {
00210                         // Clear DB
00211                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00212 
00213                         // Preparations
00214                         int expectedCount = 3;
00215 
00216                         Region[] expectedRegions = new Region[expectedCount];
00217                         for (int i = 0; i < expectedCount - 1; i++)
00218                                 expectedRegions[i] = TestUtilities.NewTestRegionWithSave(i);
00219 
00220                         // Test
00221                         Regions checkRegions = UserManagement.Regions;
00222 
00223                         // Checks
00224                         Assert.AreEqual(expectedCount, checkRegions.Count, "Wrong Regions count:");
00225 
00226                         for (int i = 0; i < expectedCount - 1; i++)
00227                                 Assert.AreEqual(expectedRegions[i].Name, checkRegions[expectedRegions[i].Name].Name);
00228 
00229                         // Restore to previous state
00230                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00231                 }
00232                 [Test]
00233                 public void Facilities()
00234                 {
00235                         // Clear DB
00236                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00237 
00238                         // Preparations
00239                         int expectedCount = 4;
00240 
00241                         Facility[] expectedFacilities = new Facility[expectedCount];
00242                         for (int i = 0; i < expectedCount - 1; i++)
00243                         {
00244                                 Region region = TestUtilities.NewTestRegionWithSave(i);
00245                                 District district = TestUtilities.NewTestDistrictWithSave(i, region);
00246                                 expectedFacilities[i] = TestUtilities.NewTestFacilityWithSave(i, region, district);
00247                         }
00248 
00249                         // Test
00250                         Facilities checkFacilities = UserManagement.Facilities;
00251 
00252                         // Checks
00253                         Assert.AreEqual(expectedCount, checkFacilities.Count, "Wrong Facilities count:");
00254 
00255                         for (int i = 0; i < expectedCount - 1; i++)
00256                                 Assert.AreEqual(expectedFacilities[i].Name, checkFacilities[expectedFacilities[i].Name].Name);
00257 
00258                         // Restore to previous state
00259                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00260                 }
00261                 #endregion
00262 
00263                 #region Public Methods
00264                 [Test]
00265                 public void GetUserData()
00266                 {
00267                         // Clear DB
00268                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00269 
00270                         // Preparations
00271                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00272 
00273                         // Test
00274                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00275 
00276                         // Checks
00277                         Assert.AreEqual(expectedUser.Name, checkUser.Name);
00278                         Assert.AreEqual(expectedUser.Login, checkUser.Login);
00279                         Assert.AreEqual(expectedUser.Password, checkUser.Password);
00280                         Assert.AreEqual(expectedUser.CompleteName, checkUser.CompleteName);
00281                         Assert.AreEqual(expectedUser.Email, checkUser.Email);
00282                         Assert.AreEqual(expectedUser.Locked, checkUser.Locked);
00283                         Assert.AreEqual(expectedUser.Type, checkUser.Type);
00284                         Assert.AreEqual(expectedUser.FunctionalRole.Name, checkUser.FunctionalRole.Name);
00285                         Assert.AreEqual(expectedUser.DataRole.Name, checkUser.DataRole.Name);
00286 
00287                         // Restore to previous state
00288                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00289                 }
00290                 [Test]
00291                 public void UserExists()
00292                 {
00293                         // Clear DB
00294                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00295 
00296                         // Preparations
00297                         bool returnStatus;
00298 
00299                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00300 
00301                         // Test
00302                         returnStatus = UserManagement.UserExists(expectedUser.Login);
00303 
00304                         // Checks
00305                         Assert.IsTrue(returnStatus, "UserExists return code:");
00306 
00307                         // Restore to previous state
00308                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00309                 }
00310                 [Test]
00311                 public void AddUser()
00312                 {
00313                         // Clear DB
00314                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00315 
00316                         // Preparations
00317                         bool returnStatus;
00318                         string errorMessage = "";
00319 
00320                         UserData expectedUser = TestUtilities.NewTestUser(1);
00321 
00322                         // Test
00323                         returnStatus = UserManagement.AddUser(expectedUser, ref errorMessage);
00324 
00325                         // Checks
00326                         Assert.IsTrue(returnStatus);
00327 
00328                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00329                         Assert.AreEqual(expectedUser.Name, checkUser.Name);
00330                         Assert.AreEqual(expectedUser.Login, checkUser.Login);
00331                         Assert.AreEqual(expectedUser.Password, checkUser.Password);
00332                         Assert.AreEqual(expectedUser.CompleteName, checkUser.CompleteName);
00333                         Assert.AreEqual(expectedUser.Email, checkUser.Email);
00334                         Assert.AreEqual(expectedUser.Locked, checkUser.Locked);
00335                         Assert.AreEqual(expectedUser.Type, checkUser.Type);
00336                         Assert.AreEqual(expectedUser.FunctionalRole.Name, checkUser.FunctionalRole.Name);
00337                         Assert.AreEqual(expectedUser.DataRole.Name, checkUser.DataRole.Name);
00338 
00339                         // Restore to previous state
00340                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00341                 }
00342                 [Test]
00343                 public void ModifyUserName()
00344                 {
00345                         // Clear DB
00346                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00347 
00348                         // Preparations
00349                         bool returnStatus;
00350                         string errorMessage = "";
00351                         string expectedName = "Changed Test User Name";
00352 
00353                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00354                         expectedUser.Name = expectedName;
00355 
00356                         // Test
00357                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00358 
00359                         // Checks
00360                         Assert.IsTrue(returnStatus);
00361 
00362                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00363                         Assert.AreEqual(expectedUser.Name, checkUser.Name);
00364                         Assert.AreEqual(checkUser.Name, checkUser.CompleteName);
00365 
00366                         // Restore to previous state
00367                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00368                 }
00369                 [Test]
00370                 public void ModifyUserLogin()
00371                 {
00372                         // Clear DB
00373                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00374 
00375                         // Preparations
00376                         bool returnStatus;
00377                         string errorMessage = "";
00378                         string expectedLogin = "changedTestLogin";
00379 
00380                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00381                         expectedUser.Login = expectedLogin;
00382 
00383                         // Test
00384                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00385 
00386                         // Checks
00387                         Assert.IsTrue(returnStatus);
00388 
00389                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00390                         Assert.AreEqual(expectedUser.Login, checkUser.Login);
00391 
00392                         // Restore to previous state
00393                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00394                 }
00395                 [Test]
00396                 public void ModifyUserPassword()
00397                 {
00398                         // Clear DB
00399                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00400 
00401                         // Preparations
00402                         bool returnStatus;
00403                         string errorMessage = "";
00404                         string expectedPassword = "changedPassword";
00405 
00406                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00407                         expectedUser.Password = expectedPassword;
00408 
00409                         // Test
00410                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00411 
00412                         // Checks
00413                         Assert.IsTrue(returnStatus);
00414 
00415                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00416                         Assert.AreEqual(expectedUser.Password, checkUser.Password);
00417 
00418                         // Restore to previous state
00419                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00420                 }
00421                 [Test]
00422                 public void ModifyUserCompleteName()
00423                 {
00424                         // Clear DB
00425                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00426 
00427                         // Preparations
00428                         bool returnStatus;
00429                         string errorMessage = "";
00430                         string expectedCompleteName = "Changed Test User Complete Name";
00431 
00432                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00433                         expectedUser.CompleteName = expectedCompleteName;
00434 
00435                         // Test
00436                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00437 
00438                         // Checks
00439                         Assert.IsTrue(returnStatus);
00440 
00441                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00442                         Assert.AreEqual(expectedUser.CompleteName, checkUser.CompleteName);
00443                         Assert.AreEqual(checkUser.Name, checkUser.CompleteName);
00444 
00445                         // Restore to previous state
00446                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00447                 }
00448                 [Test]
00449                 public void ModifyUserEmail()
00450                 {
00451                         // Clear DB
00452                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00453 
00454                         // Preparations
00455                         bool returnStatus;
00456                         string errorMessage = "";
00457                         string expectedEmail = "changed@email.com";
00458 
00459                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00460                         expectedUser.Email = expectedEmail;
00461 
00462                         // Test
00463                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00464 
00465                         // Checks
00466                         Assert.IsTrue(returnStatus);
00467 
00468                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00469                         Assert.AreEqual(expectedUser.Email, checkUser.Email);
00470 
00471                         // Restore to previous state
00472                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00473                 }
00474                 /*[Test]
00475                 public void ModifyUserLocked()
00476                 {
00477                         // Clear DB
00478                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00479 
00480                         // Preparations
00481                         bool returnStatus;
00482                         string errorMessage = "";
00483                         bool expectedLocked = true;
00484 
00485                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00486                         expectedUser.Locked = expectedLocked;
00487 
00488                         // Test
00489                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00490 
00491                         // Checks
00492                         Assert.IsTrue(returnStatus);
00493 
00494                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00495                         Assert.AreEqual(expectedUser.Locked, checkUser.Locked);
00496 
00497                         // Restore to previous state
00498                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00499                 }*/
00500                 [Test]
00501                 public void ModifyUserType()
00502                 {
00503                         // Clear DB
00504                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00505 
00506                         // Preparations
00507                         bool returnStatus;
00508                         string errorMessage = "";
00509                         string expectedTypeText = "Licensee";
00510 
00511                         UserData expectedUser = TestUtilities.NewTestUserWithSave(1);
00512                         expectedUser.TypeText = expectedTypeText;
00513 
00514                         // Test
00515                         returnStatus = UserManagement.ModifyUser(expectedUser, ref errorMessage);
00516 
00517                         // Checks
00518                         Assert.IsTrue(returnStatus);
00519 
00520                         UserData checkUser = UserManagement.GetUserData(expectedUser.Login);
00521                         Assert.AreEqual(expectedUser.TypeText, checkUser.TypeText);
00522                         Assert.AreEqual(expectedUser.Type, checkUser.Type);
00523 
00524                         // Restore to previous state
00525                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00526                 }
00527                 [Test]
00528                 public void AddDataRole()
00529                 {
00530                         // Clear DB
00531                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00532 
00533                         // Preparations
00534                         bool returnStatus;
00535                         string errorMessage = "";
00536 
00537                         DataRole expectedDataRole = TestUtilities.NewDataRoleObject(1);
00538 
00539                         // Test
00540                         returnStatus = UserManagement.AddDataRole(expectedDataRole.Name, ref errorMessage);
00541 
00542                         // Checks
00543                         Assert.IsTrue(returnStatus, "AddDataRole return status:");
00544 
00545                         DataRole checkDataRole = UserManagement.DataRoles[expectedDataRole.Name];
00546                         Assert.AreEqual(expectedDataRole.Name, checkDataRole.Name);
00547 
00548                         // Restore to previous state
00549                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00550                 }
00551                 [Test]
00552                 public void AddDataRoleAttribute()
00553                 {
00554                         // Clear DB
00555                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00556 
00557                         // Preparations
00558                         bool returnStatus;
00559                         string errorMessage = "";
00560 
00561                         DataRole expectedDataRole = TestUtilities.NewTestDataRoleWithSave(1);
00562                         DataRoleAttribute expectsdDataRoleAttribute = TestUtilities.NewTestDataRoleAttribute(1);
00563 
00564                         // Test
00565                         returnStatus = UserManagement.AddDataRoleAttribute(expectedDataRole, expectsdDataRoleAttribute, ref errorMessage);
00566 
00567                         // Checks
00568                         Assert.IsTrue(returnStatus, "AddDataRoleAttribute return status:");
00569 
00570                         DataRole checkDataRole = UserManagement.DataRoles[expectedDataRole.Name];
00571                         DataRoleAttribute checkDataRoleAttribute = checkDataRole.Attributes[expectsdDataRoleAttribute.ToString()];
00572                         Assert.AreEqual(1, checkDataRole.Attributes.Count);
00573                         Assert.AreEqual(expectsdDataRoleAttribute.Region.ID, checkDataRoleAttribute.Region.ID);
00574                         Assert.AreEqual(expectsdDataRoleAttribute.District.ID, checkDataRoleAttribute.District.ID);
00575                         Assert.AreEqual(expectsdDataRoleAttribute.Facility.ID, checkDataRoleAttribute.Facility.ID);
00576                         Assert.AreEqual(expectsdDataRoleAttribute.ToString(), checkDataRoleAttribute.ToString());
00577 
00578                         // Restore to previous state
00579                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00580                 }
00581                 [Test]
00582                 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
00583                 public void RemoveDataRoleAttribute()
00584                 {
00585                         // Clear DB
00586                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00587 
00588                         // Preparations
00589                         bool returnStatus;
00590                         string errorMessage = "";
00591 
00592                         DataRole expectedDataRole = TestUtilities.NewTestDataRoleWithSave(1);
00593                         DataRoleAttribute expectsdDataRoleAttribute = TestUtilities.NewTestDataRoleAttribute(1);
00594                         returnStatus = UserManagement.AddDataRoleAttribute(expectedDataRole, expectsdDataRoleAttribute, ref errorMessage);
00595                         if (!returnStatus)
00596                                 throw new Exception("Add Data Role Attribute Error");
00597                         DataRole checkDataRole = UserManagement.DataRoles[expectedDataRole.Name];
00598                         DataRoleAttribute checkDataRoleAttribute = checkDataRole.Attributes[expectsdDataRoleAttribute.ToString()];
00599 
00600                         // Test
00601                         returnStatus = UserManagement.RemoveDataRoleAttribute(checkDataRole, checkDataRoleAttribute, ref errorMessage);
00602 
00603                         // Checks
00604                         Assert.IsTrue(returnStatus, "RemoveDataRoleAttribute return status:");
00605 
00606                         try
00607                         {
00608                                 // Check that DataRoleAttribute does not exist in DataRoleAttributes dictionary
00609                                 // Expected exception System.Collections.Generic.KeyNotFoundException
00610                                 checkDataRole = UserManagement.DataRoles[expectedDataRole.Name];
00611                                 checkDataRoleAttribute = checkDataRole.Attributes[expectsdDataRoleAttribute.ToString()];
00612                         }
00613                         finally
00614                         {
00615                                 // Restore to previous state
00616                                 Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00617                         }
00618                 }
00619                 [Test]
00620                 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
00621                 public void RemoveDataRole()
00622                 {
00623                         // Clear DB
00624                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00625 
00626                         // Preparations
00627                         bool returnStatus;
00628                         string errorMessage = "";
00629 
00630                         DataRole expectedDataRole = TestUtilities.NewTestDataRoleWithSave(1);
00631 
00632                         // Test
00633                         returnStatus = UserManagement.RemoveDataRole(expectedDataRole, ref errorMessage);
00634 
00635                         // Checks
00636                         Assert.IsTrue(returnStatus, "RemoveDataRole return status:");
00637 
00638                         try
00639                         {
00640                                 // Check that DataRole does not exist in DataRoles dictionary
00641                                 // Expected exception System.Collections.Generic.KeyNotFoundException
00642                                 DataRole checkDataRole = UserManagement.DataRoles[expectedDataRole.Name];
00643                                 Assert.AreEqual(expectedDataRole.Name, checkDataRole.Name);
00644                         }
00645                         finally
00646                         {
00647                                 // Restore to previous state
00648                                 Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00649                         }
00650                 }
00651                 [Test]
00652                 public void AddFunctionRole()
00653                 {
00654                         // Clear DB
00655                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00656 
00657                         // Preparations
00658                         bool returnStatus;
00659                         string errorMessage = "";
00660 
00661                         FunctionRole expectedFunctionRole = TestUtilities.NewFunctionRoleObject(1);
00662 
00663                         // Test
00664                         returnStatus = UserManagement.AddFunctionRole(expectedFunctionRole.Name, ref errorMessage);
00665 
00666                         // Checks
00667                         Assert.IsTrue(returnStatus, "AddFunctionRole return status:");
00668 
00669                         FunctionRole checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00670                         Assert.AreEqual(expectedFunctionRole.Name, checkFunctionRole.Name);
00671                         Assert.AreEqual(expectedFunctionRole.Validation, checkFunctionRole.Validation);
00672 
00673                         // Restore to previous state
00674                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00675                 }
00676                 [Test]
00677                 public void SaveFunctionRole()
00678                 {
00679                         // Clear DB
00680                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00681 
00682                         // Preparations
00683                         bool returnStatus;
00684                         string errorMessage = "";
00685 
00686                         FunctionRole expectedFunctionRole = TestUtilities.NewTestFunctionRoleWithSave(1);
00687                         expectedFunctionRole.Validation = FunctionRole.ValidationType.DoesNotNeedValidation;
00688 
00689                         // Test
00690                         returnStatus = UserManagement.SaveFunctionRole(expectedFunctionRole, ref errorMessage);
00691 
00692                         // Checks
00693                         Assert.IsTrue(returnStatus, "RemoveFunctionRole return status:");
00694 
00695                         FunctionRole checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00696                         Assert.AreEqual(expectedFunctionRole.Validation, checkFunctionRole.Validation);
00697 
00698                         // Restore to previous state
00699                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00700                 }
00701                 [Test]
00702                 public void AddFunctionRoleAttribute()
00703                 {
00704                         // Clear DB
00705                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00706 
00707                         // Preparations
00708                         bool returnStatus;
00709                         string errorMessage = "";
00710 
00711                         FunctionRole expectedFunctionRole = TestUtilities.NewTestFunctionRoleWithSave(1);
00712                         FunctionRoleAttribute expectsdFunctionRoleAttribute = TestUtilities.NewTestFunctionRoleAttribute(1);
00713 
00714                         // Test
00715                         returnStatus = UserManagement.AddFunctionRoleAttribute(expectedFunctionRole, expectsdFunctionRoleAttribute, ref errorMessage);
00716 
00717                         // Checks
00718                         Assert.IsTrue(returnStatus, "AddFunctionRoleAttribute return status:");
00719 
00720                         FunctionRole checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00721                         FunctionRoleAttribute checkFunctionRoleAttribute = checkFunctionRole.Attributes[expectsdFunctionRoleAttribute.ToString()];
00722                         Assert.AreEqual(1, checkFunctionRole.Attributes.Count);
00723                         Assert.AreEqual(expectsdFunctionRoleAttribute.Category.ID, checkFunctionRoleAttribute.Category.ID);
00724                         Assert.AreEqual(expectsdFunctionRoleAttribute.Subcategory.ID, checkFunctionRoleAttribute.Subcategory.ID);
00725                         Assert.AreEqual(expectsdFunctionRoleAttribute.Mask.ID, checkFunctionRoleAttribute.Mask.ID);
00726                         Assert.AreEqual(expectsdFunctionRoleAttribute.ToString(), checkFunctionRoleAttribute.ToString());
00727 
00728                         // Restore to previous state
00729                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00730                 }
00731                 [Test]
00732                 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
00733                 public void RemoveFunctionRoleAttribute()
00734                 {
00735                         // Clear DB
00736                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00737 
00738                         // Preparations
00739                         bool returnStatus;
00740                         string errorMessage = "";
00741 
00742                         FunctionRole expectedFunctionRole = TestUtilities.NewTestFunctionRoleWithSave(1);
00743                         FunctionRoleAttribute expectsdFunctionRoleAttribute = TestUtilities.NewTestFunctionRoleAttribute(1);
00744                         returnStatus = UserManagement.AddFunctionRoleAttribute(expectedFunctionRole, expectsdFunctionRoleAttribute, ref errorMessage);
00745                         if (!returnStatus)
00746                                 throw new Exception("Add Function Role Attribute Error");
00747                         FunctionRole checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00748                         FunctionRoleAttribute checkFunctionRoleAttribute = checkFunctionRole.Attributes[expectsdFunctionRoleAttribute.ToString()];
00749 
00750                         // Test
00751                         returnStatus = UserManagement.RemoveFunctionRoleAttribute(checkFunctionRole, checkFunctionRoleAttribute, ref errorMessage);
00752 
00753                         // Checks
00754                         Assert.IsTrue(returnStatus, "RemoveFunctionRoleAttribute return status:");
00755 
00756                         try
00757                         {
00758                                 // Check that FunctionRoleAttribute does not exist in FunctionRoleAttributes dictionary
00759                                 // Expected exception System.Collections.Generic.KeyNotFoundException
00760                                 checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00761                                 checkFunctionRoleAttribute = checkFunctionRole.Attributes[expectsdFunctionRoleAttribute.ToString()];
00762                         }
00763                         finally
00764                         {
00765                                 // Restore to previous state
00766                                 Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00767                         }
00768                 }
00769                 [Test]
00770                 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
00771                 public void RemoveFunctionRole()
00772                 {
00773                         // Clear DB
00774                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00775 
00776                         // Preparations
00777                         bool returnStatus;
00778                         string errorMessage = "";
00779 
00780                         FunctionRole expectedFunctionRole = TestUtilities.NewTestFunctionRoleWithSave(1);
00781 
00782                         // Test
00783                         returnStatus = UserManagement.RemoveFunctionRole(expectedFunctionRole, ref errorMessage);
00784 
00785                         // Checks
00786                         Assert.IsTrue(returnStatus, "RemoveFunctionRole return status:");
00787 
00788                         try
00789                         {
00790                                 // Check that FunctionRole does not exist in FunctionRoles dictionary
00791                                 // Expected exception System.Collections.Generic.KeyNotFoundException
00792                                 FunctionRole checkFunctionRole = UserManagement.FunctionalRoles[expectedFunctionRole.Name];
00793                                 Assert.AreEqual(expectedFunctionRole.Name, checkFunctionRole.Name);
00794                         }
00795                         finally
00796                         {
00797                                 // Restore to previous state
00798                                 Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00799                         }
00800                 }
00801                 [Test]
00802                 public void GetDistrictsByRegion()
00803                 {
00804                         // Clear DB
00805                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00806 
00807                         // Preparations
00808                         int expectedCount = 3;
00809 
00810                         District[] expectedDistricts = new District[expectedCount];
00811                         Region region = TestUtilities.NewTestRegionWithSave(1);
00812                         for (int i = 0; i < expectedCount - 1; i++)
00813                                 expectedDistricts[i] = TestUtilities.NewTestDistrictWithSave(i, region);
00814 
00815                         // Test
00816                         Districts checkDistricts = UserManagement.GetDistrictsByRegion(region);
00817 
00818                         // Checks
00819                         Assert.AreEqual(expectedCount, checkDistricts.Count, "Wrong Districts count:");
00820 
00821                         for (int i = 0; i < expectedCount - 1; i++)
00822                                 Assert.AreEqual(expectedDistricts[i].Name, checkDistricts[expectedDistricts[i].Name].Name);
00823 
00824                         // Restore to previous state
00825                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00826                 }
00827                 [Test]
00828                 public void GetFacilitiesByRegionAndDistrict()
00829                 {
00830                         // Clear DB
00831                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00832 
00833                         // Preparations
00834                         int expectedCount = 4;
00835 
00836                         Facility[] expectedFacilities = new Facility[expectedCount];
00837                         Region region = TestUtilities.NewTestRegionWithSave(1);
00838                         District district = TestUtilities.NewTestDistrictWithSave(1, region);
00839                         for (int i = 0; i < expectedCount - 1; i++)
00840                         {
00841                                 expectedFacilities[i] = TestUtilities.NewTestFacilityWithSave(i, region, district);
00842                         }
00843 
00844                         // Test
00845                         Facilities checkFacilities = UserManagement.GetFacilitiesByRegionAndDistrict(region, district);
00846 
00847                         // Checks
00848                         Assert.AreEqual(expectedCount, checkFacilities.Count, "Wrong Facilities count:");
00849 
00850                         for (int i = 0; i < expectedCount - 1; i++)
00851                                 Assert.AreEqual(expectedFacilities[i].Name, checkFacilities[expectedFacilities[i].Name].Name);
00852 
00853                         // Restore to previous state
00854                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00855                 }
00856                 [Test]
00857                 public void GetFunctionalRoleSubcategories()
00858                 {
00859                         // Clear DB
00860                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00861 
00862                         // Preparations
00863                         int expectedCount = 4;
00864 
00865                         FunctionRole.Subcategory[] expectedSubcategories = new FunctionRole.Subcategory[expectedCount];
00866                         FunctionRole.Category category = TestUtilities.NewTestCategoryWithSave(1);
00867                         for (int i = 0; i < expectedCount - 1; i++)
00868                                 expectedSubcategories[i] = TestUtilities.NewTestSubcategoryWithSave(i, category);
00869 
00870                         // Test
00871                         FunctionRoleSubcategories checkSubcategories = UserManagement.GetFunctionalRoleSubcategories(category);
00872 
00873                         // Checks
00874                         Assert.AreEqual(expectedCount, checkSubcategories.Count, "Wrong Subcategories count:");
00875 
00876                         for (int i = 0; i < expectedCount - 1; i++)
00877                                 Assert.AreEqual(expectedSubcategories[i].Name, checkSubcategories[expectedSubcategories[i].Name].Name);
00878 
00879                         // Restore to previous state
00880                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00881                 }
00882                 [Test]
00883                 public void GetMasks()
00884                 {
00885                         // Clear DB
00886                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB before test error");
00887 
00888                         // Preparations
00889                         int expectedCount = 3;
00890 
00891                         Mask[] expectedMasks = new Mask[expectedCount];
00892                         FunctionRole.Category category = TestUtilities.NewTestCategoryWithSave(1);
00893                         FunctionRole.Subcategory subcategory = TestUtilities.NewTestSubcategoryWithSave(1, category);
00894                         for (int i = 0; i < expectedCount - 1; i++)
00895                                 expectedMasks[i] = TestUtilities.NewTestMaskWithSave(i, category, subcategory);
00896 
00897                         // Test
00898                         Masks checkMasks = UserManagement.GetMasks(category, subcategory);
00899 
00900                         // Checks
00901                         Assert.AreEqual(expectedCount, checkMasks.Count, "Wrong Masks count:");
00902 
00903                         for (int i = 0; i < expectedCount - 1; i++)
00904                                 Assert.AreEqual(expectedMasks[i].Name, checkMasks[expectedMasks[i].Name].Name);
00905 
00906                         // Restore to previous state
00907                         Assert.IsTrue(TestUtilities.TruncateTables(), "Clear DB after test error");
00908                 }
00909                 #endregion
00910 
00911                 #region Private Utilities
00912                 #endregion
00913         }
00914 }